package org.gitman.filmBase.view;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.gitman.filmBase.controller.Controller;
import org.gitman.filmBase.model.Model;
import org.gitman.filmBase.view.tools.SwingConsole;

public class View {
	private Model model;
	private static Logger logger = Logger.getLogger(View.class);
	private MainFrame mainFrame;
	private Controller controller;
	
	public View(Controller controller){
		this.controller = controller;
	}
	
	public Model getModel() {
		return model;
	}
	public void setModel(Model model) {
		this.model = model;
	}

	public void start(){
		String confFile = System.getProperty("conf");
		Properties properties = new Properties();
			try {
				properties.load(new FileInputStream(confFile));
				Integer width = Integer.parseInt(properties.get("mainFrame.width").toString());
				Integer height = Integer.parseInt(properties.get("mainFrame.height").toString());
				Boolean fullScreen = Boolean.parseBoolean(properties.get("mainFrame.fullScreen").toString());
				InitScreen initScreen = new InitScreen(properties);
				
				mainFrame = new MainFrame(properties, initScreen, controller);			
				SwingConsole.run(mainFrame, width, height, fullScreen);				
			
			} catch (IOException e) {
				logger.error("At start up", e);
			}
	}

	public void stop(){
		if(mainFrame != null){
			mainFrame.shutDown();
		}
	}
}
